test: catch expected UserWarning in test_repr_mimebundle_selection_logic - #17717
Conversation
There was a problem hiding this comment.
Code Review
This pull request updates the unit tests in test_render_mode.py to import pytest and assert that a UserWarning with the message 'Anywidget mode is not available' is correctly raised when anywidget fails during deferred representation rendering. I have no feedback to provide as there are no review comments.
sycai
left a comment
There was a problem hiding this comment.
Thanks! Small PRs are the best
| with bpd.option_context("display.repr_mode", "deferred"): | ||
| bundle = bf_html.repr_mimebundle(mock_obj) | ||
| with pytest.warns(UserWarning, match="Anywidget mode is not available"): | ||
| bundle = bf_html.repr_mimebundle(mock_obj) |
There was a problem hiding this comment.
I think you can chain multiple context managers in a single "with" statement, separated with commas:
with bpd.option_context(...), pytest.warns(...):
bundle = ...Let see if that works
There was a problem hiding this comment.
Good suggestions. I have applied the same changes to all anywidget related testcase. Thanks again for your suggestions.
|
The failed tests are unrelated to our code change. I have failed a bug to the code owner to get the failed testcase resolved. |
Assert expected
UserWarningduring the fallback path test intest_repr_mimebundle_selection_logic.When testing fallback behavior on
anywidgetfailure,html.repr_mimebundleemits a warning (Anywidget mode is not available or failed to load). This change usespytest.warns(UserWarning, match=...)to handle the warning cleanly in unit tests.Fixes #<534917716> 🦕